﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using SharePoint.Contrib.Extensions;
using SharePoint.Contrib;

namespace NUnit.SharePointContrib
{
    [TestFixture]
    public class GenericDataConverterTest
    {

        [SetUp]
        public void Init()
        {
            
        }

        [TearDown]
        public void Dispose()
        {
        }


        [Test]
        public void CanConvertStringToDateTime()
        {
            var sDateTime = "2010-02-08";
            var dtDateTime = GenericDataConverter<DateTime>.Convert(sDateTime);

            Assert.That(dtDateTime.GetType(), Is.EqualTo(typeof(DateTime)));
            Assert.That(dtDateTime.ToString("yyyy-MM-dd"), Is.EqualTo("2010-02-08"));

        }

        [Test]
        public void CanConvertStringToInteger()
        {
            var sInt = "10";
            var iInt = GenericDataConverter<int>.Convert(sInt);

            Assert.That(iInt.GetType(), Is.EqualTo(typeof(int)));
            Assert.That(iInt, Is.EqualTo(10));

        }

        [Test]
        public void CanConverToNullableType()
        {
            var nullable = GenericDataConverter<Nullable<int>>.Convert(null);
            Assert.Null(nullable);

        }

       
    }
}
